package com.example.travel_front.Fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.travel_front.Adapter.NewsAdapter;
import com.example.travel_front.Model.News;
import com.example.travel_front.R;

import java.util.ArrayList;
import java.util.List;

public class NewsFragment extends Fragment {

    public NewsFragment() {
        // Required empty public constructor
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_news, container, false);

        RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        List<News> newsList = displayList(); // 这个方法负责获取新闻数据
        NewsAdapter adapter = new NewsAdapter(newsList, getContext());
        recyclerView.setAdapter(adapter);

        return view;
    }






    @Override
    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }


    private List<News> getNewsList() {
        // TODO: 实现从数据库或API获取护理之家列表的逻辑
        return new ArrayList<>();
    }

    public List<News> displayList() {
        List<News> fakeNewsList = new ArrayList<>();

        fakeNewsList.add(new News(
                "Community Event This Weekend",
                "Join us this weekend for a fun community event featuring local bands, food trucks, and games for all ages.",
                "https://jdhn.oss-cn-hangzhou.aliyuncs.com/1.jpg",
                "Saturday, 12 PM to 5 PM",
                "Central Park",1
        ));

        fakeNewsList.add(new News(
                "New Library Opening",
                "The new downtown library will be opening next week. Come explore the modern facilities and diverse collection.",
                "https://jdhn.oss-cn-hangzhou.aliyuncs.com/2.jpg",
                "Monday, 9 AM",
                "Downtown Library",2
        ));

        fakeNewsList.add(new News(
                "Charity Marathon",
                "Register now for the annual charity marathon. All proceeds will go to local charities supporting community health.",
                "https://jdhn.oss-cn-hangzhou.aliyuncs.com/3.jpg",
                "Sunday, 7 AM to 2 PM",
                "Riverfront Plaza",3
        ));

        return fakeNewsList;
    }

}
